home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 050 / rotater.arc / ROTATER.PAS < prev   
Encoding:
Pascal/Delphi Source File  |  1985-12-23  |  7.7 KB  |  308 lines

  1. {Program by Stan Mros written in Turbo Pascal}
  2. {For IBM color graphics card in Turbo Graphix Toolbox}
  3. {Free public distribution encouraged}
  4.  
  5. program rotater;
  6. {$I typedef.sys}
  7. {$I graphix.sys}
  8. {$I kernel.sys}
  9. {$I windows.sys}
  10.  
  11.  
  12. const
  13.  
  14.     radians: real=0.0785398; {1/80 of a rotation}
  15.     radiansn: real=6.2046456; {-1/80 of a rotation}
  16.     sqrof2: real=1.414214;   {used in displaying pts.}
  17.     maxpts=100;
  18.     maxconnect=150;
  19.     numofrotations=80;
  20.  
  21. type
  22.     coordinate=real;
  23.     distance=real;
  24.  
  25. var
  26.     xplot1,yplot1,xplot2,yplot2:array [1..maxconnect] of integer;
  27.     xt,yt,zt,xcor,ycor,zcor:array [1..maxpts] of coordinate;
  28.     pt1,pt2:array [1..maxconnect] of integer;
  29.     xlow,ylow,xhigh,yhigh:integer;
  30.  
  31.     choice,rotation:char;
  32.     numofpts,numofconnect,counter:integer;
  33.     xangle,yangle,zangle,cosofang,cosofang90:real;
  34.  
  35. procedure setup;
  36. begin;
  37. xhigh:=-1000;
  38. yhigh:=-1000;
  39. xlow:=1000;
  40. ylow:=1000;
  41. xangle:=0;
  42. yangle:=0;
  43. zangle:=0;
  44. end;
  45.  
  46. procedure rotatex;
  47. var
  48.    count2:integer;
  49. begin;
  50.       for count2:=1 to numofpts do begin;
  51.           zcor[count2]:=trunc(zt[count2]*cos(xangle)-yt[count2]*sin(xangle));
  52.           ycor[count2]:=trunc(zt[count2]*sin(xangle)+yt[count2]*cos(xangle));
  53.           xcor[count2]:=trunc(xt[count2]);
  54.       end;
  55. end;
  56.  
  57. procedure rotatey;
  58. var
  59.    count2:integer;
  60. begin;
  61.       for count2:=1 to numofpts do begin;
  62.           xcor[count2]:=trunc(xt[count2]*cos(yangle)-zt[count2]*sin(yangle));
  63.           zcor[count2]:=trunc(xt[count2]*sin(yangle)+zt[count2]*cos(yangle));
  64.           ycor[count2]:=trunc(yt[count2]);
  65.       end;
  66. end;
  67.  
  68. procedure rotatez;
  69. var
  70.    count2:integer;
  71. begin;
  72.       for count2:=1 to numofpts do begin;
  73.           ycor[count2]:=trunc(yt[count2]*cos(zangle)-xt[count2]*sin(zangle));
  74.           xcor[count2]:=trunc(yt[count2]*sin(zangle)+xt[count2]*cos(zangle));
  75.           zcor[count2]:=trunc(zt[count2]);
  76.       end;
  77. end;
  78.  
  79. procedure rotate;
  80. begin;
  81.     case rotation of
  82.          '1':begin;
  83.                  xangle:=xangle+radians;
  84.                  rotatex;
  85.              end;
  86.          '2':begin;
  87.                  xangle:=xangle+radiansn;
  88.                  rotatex;
  89.              end;
  90.          '3':begin;
  91.                  yangle:=yangle+radians;
  92.                  rotatey;
  93.              end;
  94.          '4':begin;
  95.                  yangle:=yangle+radiansn;
  96.                  rotatey;
  97.              end;
  98.          '5':begin;
  99.                  zangle:=zangle+radians;
  100.                  rotatez;
  101.              end;
  102.          '6':begin;
  103.                  zangle:=zangle+radiansn;
  104.                  rotatez;
  105.              end;
  106.          end;
  107. end;
  108.  
  109. procedure findpoints;
  110. var
  111.    loop1:integer;
  112. begin;
  113. for loop1:=1 to numofconnect do begin;
  114.         xplot1[loop1]:=trunc(xcor[pt1[loop1]]-trunc(ycor[pt1[loop1]]/sqrof2));
  115.         yplot1[loop1]:=trunc(zcor[pt1[loop1]]+trunc(ycor[pt1[loop1]]/sqrof2));
  116.         xplot2[loop1]:=trunc(xcor[pt2[loop1]]-trunc(ycor[pt2[loop1]]/sqrof2));
  117.         yplot2[loop1]:=trunc(zcor[pt2[loop1]]+trunc(ycor[pt2[loop1]]/sqrof2));
  118. end;
  119. end;
  120.  
  121. procedure findmaxmin;
  122. var
  123.    loop1,loop2:integer;
  124. begin;
  125. setup;
  126. for loop2:=1 to numofrotations do begin;
  127.     rotate;
  128.     for loop1:=1 to numofconnect do begin;
  129.         findpoints;
  130.         if xplot1[loop1]<xlow then xlow:=xplot1[loop1];
  131.         if xplot2[loop1]<xlow then xlow:=xplot2[loop1];
  132.         if xplot1[loop1]>xhigh then xhigh:=xplot1[loop1];
  133.         if xplot2[loop1]>xhigh then xhigh:=xplot2[loop1];
  134.         if yplot1[loop1]<ylow then ylow:=yplot1[loop1];
  135.         if yplot2[loop1]<ylow then ylow:=yplot2[loop1];
  136.         if yplot1[loop1]>yhigh then yhigh:=yplot1[loop1];
  137.         if yplot2[loop1]>yhigh then yhigh:=yplot2[loop1];
  138.     end;
  139. end;
  140. defineworld(1,xlow,ylow,xhigh,yhigh);
  141. end;
  142.  
  143. procedure drawptsinwindow;
  144.      var loop1,loop2:integer;
  145. begin;
  146. setup;
  147.     for loop1:=1 to numofrotations do begin;
  148.     definewindow(loop1,trunc(xmaxglb*1/5),trunc(ymaxglb*1/5),trunc(xmaxglb*2/5),trunc(ymaxglb*2/5));
  149.     selectworld(1);
  150.     selectwindow(loop1);
  151.     rotate;
  152.     findpoints;
  153.     clearscreen;
  154.             for loop2:=1 to numofconnect do begin;
  155.             drawline(xplot1[loop2],yplot1[loop2],xplot2[loop2],yplot2[loop2]);
  156.         end;
  157.         storewindow(loop1);
  158.     end;
  159. end;
  160.  
  161. procedure displaypts;
  162. var
  163.    rot,loop1,loop2:integer;
  164. begin;
  165. clearscreen;
  166. gotoxy(1,1);
  167. write('Enter the number of complete rotations:');readln(rot);
  168. entergraphic;
  169. clearscreen;
  170. for loop2:=1 to rot do begin;
  171.     for loop1:=1 to numofrotations do begin;
  172.         restorewindow(loop1,0,0);
  173.         end;
  174.     end;
  175. leavegraphic;
  176. end;
  177.  
  178. procedure rotateandsave;
  179. begin;
  180.       entergraphic;
  181.       findmaxmin;
  182.       drawptsinwindow;
  183.       leavegraphic;
  184. end;
  185.  
  186. procedure enterrotations;
  187. var
  188.    loop1:integer;
  189.    rot:char;
  190. begin;
  191. clearscreen;
  192. gotoxy(1,1);writeln('   types of rotations:');
  193. writeln('');
  194. writeln('(1) Counter clockwise around X axis');
  195. writeln('(2) Clockwise around X axis');
  196. writeln('(3) Counter clockwise around Y axis');
  197. writeln('(4) Clockwise around Y axis');
  198. writeln('(5) Counter clockwise around Z axis');
  199. writeln('(6) Clockwise around Z axis');
  200. gotoxy(5,16);write('Enter the number of the rotation:');
  201.       read(kbd,rotation);
  202. end;
  203.  
  204. procedure enterpts;
  205. begin;
  206. repeat;
  207.       gotoxy(4,4);
  208.       write('enter the number of points: ');
  209.       readln(numofpts);
  210. until numofpts<maxpts;
  211. for counter:=1 to numofpts do begin;
  212.     gotoxy(4,6);write('entering values for point ');write(counter);
  213.     gotoxy(7,9);write('enter X value:');readln(xt[counter]);
  214.     gotoxy(7,10);write('enter Y value:');readln(yt[counter]);
  215.     gotoxy(7,11);write('enter Z value:');readln(zt[counter]);
  216.     gotoxy(21,9);write('     ');
  217.     gotoxy(21,10);write('     ');
  218.     gotoxy(21,11);write('     ');
  219. end;
  220. end;
  221.  
  222. procedure enterconnections;
  223. begin;
  224. repeat;
  225.        gotoxy(5,4);
  226.        write('enter the number of connections:');
  227.        readln(numofconnect);
  228. until numofconnect<=maxconnect;
  229. for counter:=1 to numofconnect do begin;
  230.     gotoxy(6,6);write('connection number ');
  231.     write(counter);
  232.     gotoxy(8,8);write('first point for connection: ');
  233.     readln(pt1[counter]);
  234.     gotoxy(8,9);write('second point for connection: ');
  235.     readln(pt2[counter]);
  236.     gotoxy(34,8);writeln('     ');
  237.     gotoxy(35,9);writeln('     ');
  238. end;
  239. end;
  240.  
  241. procedure drawmenu;
  242. begin;
  243. clearscreen;
  244. gotoxy(10,3);writeln('(1) Enter the points');
  245. gotoxy(10,5);writeln('(2) Enter the connections');
  246. gotoxy(10,7);writeln('(3) Enter the rotation pattern');
  247. gotoxy(10,9);writeln('(4) Rotate and save in windows');
  248. gotoxy(10,11);writeln('(5) display points in windows');
  249. gotoxy(10,13);writeln('(6) save window stack');
  250. gotoxy(10,15);writeln('(7) load window stack');
  251. gotoxy(10,17);writeln('(8) quit');
  252. gotoxy(20,19);writeln('enter choice >');
  253. end;
  254.  
  255. procedure saveit;
  256. var
  257.    stackname:string [8];
  258. begin;
  259. clearscreen;
  260. gotoxy(1,1);
  261. write('Enter name to be given to stack (no extension required):');
  262. readln(stackname);
  263. savewindowstack(stackname);
  264. end;
  265.  
  266. procedure loadit;
  267. var
  268.    stackname:string [8];
  269. begin;
  270. clearscreen;
  271. gotoxy(1,1);
  272. write('Enter name of existing stack (no extension required):');
  273. readln(stackname);
  274. loadwindowstack(stackname);
  275. end;
  276.  
  277. procedure menu;
  278. begin;
  279. drawmenu;
  280. choice:='0';
  281. repeat;
  282.        read(kbd,choice);
  283.        gotoxy(34,19);write(choice);
  284.        until choice in ['1','2','3','4','5','6','7','8'];
  285. clearscreen;
  286. case choice of
  287.      '1':enterpts;
  288.      '2':enterconnections;
  289.      '3':enterrotations;
  290.      '4':rotateandsave;
  291.      '5':displaypts;
  292.      '6':saveit;
  293.      '7':loadit;
  294. end;
  295. clearscreen;
  296. end;
  297.  
  298.  
  299. begin; {program rotater.pas}
  300. initgraphic;
  301. leavegraphic;
  302. drawmenu;
  303. repeat;
  304.        menu;
  305. until choice='8';
  306. leavegraphic;
  307. end.
  308.